﻿using System;
using System.Collections.Generic;
using System.IO;
using BML.Infrastructure.Communicate;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SystmicFunction.Public.CharacterService;

using System.Linq;
using SystmicFunction.Public.FileService;
using SystmicFunction.Public.NetService;

namespace FrameCase
{
    [TestClass]
    public class SystmicFunctionCase
    {
        [TestMethod]
        public void MakeKeys()
        {
            String[] text = { "ABC", "你好", "你好AB", "ABCD", "ABCG" };
            var keys = Search.MakeKeys("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
            keys = keys.OrderByDescending(m => m.Length).ToArray();
            var s = from t in text
                    where keys.Any(t.Contains)
                    select t;
            foreach (var result in s.ToList())
            {
                Console.WriteLine(result);
            }

        }

        [TestMethod]
        public void SendEmail()
        {
            Email.SendMail("yan.dong@defshare.com", "垃圾-测试邮件", "测试内容", "董严", true,
                "yan.dong@defshare.com", "share123", "smtp.exmail.qq.com", false, true);
        }

        [TestMethod]
        public void QrCode()
        {
            QrCodeHelper.Make("很抱歉，客户端正在建设", @"c:\Test_Temp\CaseQrcode.png");
        }

        [TestMethod]
        public void QrCodeWithLogo()
        {
            QrCodeHelper.MakewithLogo(@"C:\Temp\ico5.png", @"http://www.kdkdm.com/Home/AppDownload", @"C:\Temp\Qrcode.Jpeg", 2);
        }

        [TestMethod]
        public void SaveExl()
        {
            var source = new List<SouceData>();
            for (int i = 0; i < 10; i++)
            {
                source.Add(new SouceData
                {
                    CreateTime = DateTime.Now,
                    Id = Guid.NewGuid(),
                    Name = "name",
                    None = true,
                    Statue = 1
                });
            }

            String[] names = { "Id", "Name", "CreateTime" };

            OfficeHelper.SaveExl(@"d:\CaseExl.xls", "测试表1", source, names);
        }

        [TestMethod]
        public void Lamda()
        {
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
            var firstSmallNumbers = numbers.TakeWhile((n, index) => n >= index);

            Console.WriteLine(firstSmallNumbers);
        }

        [TestMethod]
        public void Savexml()
        {

            FileHelper.SaveXml(@"C:\Temp\Menu1.xml", new List<XmlData>
            {
                new XmlData{Name = "menu",Attributes = new Dictionary<string, string>{ {"Key","WS-NS-1100"},{"Index","1100"},{"Name","最新资讯"}}},

                new XmlData{Name = "menu",Attributes = new Dictionary<string, string>{ {"Key","WS-NS-1200"},{"Index","1100-1200"},{"Name","最新信息"}}},

            });
        }

        [TestMethod]
        public void Net()
        {
            var webResponese = HttpHelper.CreateGetHttpResponse("mp.weixin.qq.com/cgi-bin/showqrcode", true, new Dictionary<string, object> { { "ticket", "gQFC8DoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL20zUXZESnptN1lPVVA5aEdYbGkwAAIEXC7KUgMEAAAAAA==" } }, null, null,
                 null);
            var stream = webResponese.GetResponseStream();

            using ( BinaryReader reader = new BinaryReader(stream))
            {
                
                Byte[] lnByte = reader.ReadBytes((Int32)webResponese.ContentLength);
                using (FileStream lxFS = new FileStream(@"C:\Temp\34891.jpg", FileMode.Create))
                {
                    lxFS.Write(lnByte, 0, lnByte.Length);
                }
            }

        }


    }

    public class SouceData
    {
        public Guid Id { get; set; }
        public String Name { get; set; }
        public DateTime CreateTime { get; set; }
        public Int32 Statue { get; set; }
        public bool None { get; set; }
    }

}
